* Table 3: INTERVENTION STOVE PURCHASE RATES

use "${output}panel_r0_r1_r2.dta", clear // Load merged analysis panel

********************************************************************************

* Keep households surveyed in each round
keep if sample_household == 1

********************************************************************************

* REGRESSIONS

// Reposition baseline value of household controls
foreach var of varlist household_size children_under_five {
	gen b_`var' = `var' if surveyround == 0
	bys hh_id (surveyround) : replace b_`var' = b_`var'[1] if mi(b_`var')
	}

// Analyses

keep if surveyround == 1

local model_1 "purchased_intervention_stove i.treatment, absorb(districtcode) vce(cluster uniquegrp) nocons"
local model_2 "purchased_intervention_stove i.treatment##i.chirag_strata, absorb(districtcode) vce(cluster uniquegrp) nocons"
local model_3 "purchased_intervention_stove i.treatment##i.chirag_strata b_*, absorb(districtcode) vce(cluster uniquegrp) nocons"

forval i = 1/3 {

	// Estimation
	reghdfe `model_`i''

	// Results matrix
	matrix table_`i' = r(table)

	// Extract regression statistics
	local N_`i' = e(N)
	local ar2_`i' = e(r2_a)
	local ar2_`i' : di %5.2f `ar2_`i''	

	// Extract regression results
	foreach x in 1.treatment 1.chirag_strata 1.treatment#1.chirag_strata {

		// Adjust name for local macros
		local y `x'
		local y = subinstr("`y'",".","",.)
		local y = subinstr("`y'","#","",.)

		* betas
		local colnum = colnumb(table_`i',"`x'")
		local b_`y'_`i' = table_`i'[1,`colnum']
		local b_`y'_`i' : di %5.2f `b_`y'_`i''

		* standard errors
		local se_`y'_`i' = table_`i'[2,`colnum']
		local se_`y'_`i' : di %4.2f `se_`y'_`i''
		local seb_`y'_`i' = "(" + "`se_`y'_`i''" + ")"

		* p-values
		local p_`y'_`i' = table_`i'[4,`colnum']
		local p_`y'_`i' : di %12.3fc `p_`y'_`i''

		* significance stars
		local st_`y'_`i' = cond(`p_`y'_`i''<0.01,"***",cond(`p_`y'_`i''<0.05,"**",cond(`p_`y'_`i''<0.1,"*","")))
		
		* betas + significance stars
		local bst_`y'_`i' = "`b_`y'_`i''" + "`st_`y'_`i''"

	}
}

* Control mean
qui sum purchased_intervention_stove if treatment == 0
local control_mean = `r(mean)'

********************************************************************************

* TABLE: EXPORT

texdoc init "${results}table_purchase_rates.tex", replace force
	tex \begin{table}[tb]
	tex \centering
	tex \caption{Effect of promotion on intervention ICS purchase in matched NGO/non-NGO villages\label{t:purchase_rates}}
	tex \begin{threeparttable}
	tex \begin{tabular}{lccc}
	tex \toprule
	tex & (1) & (2) & (3) \\ \cmidrule(lr){2-4}
	tex & \multicolumn{3}{l}{\(\mathbbm{1} \left( \text{Purchased intervention ICS} \right)\)} \\ 
	tex \midrule
	tex \({TREATMENT}_j\) & `bst_1treatment_1' & `bst_1treatment_2' & `bst_1treatment_3' \\
	tex & `seb_1treatment_1' & `seb_1treatment_2' & `seb_1treatment_3' \\
	tex \addlinespace
	tex \({NGO}_j\) & `bst_1chirag_strata_1' & `bst_1chirag_strata_2' & `bst_1chirag_strata_3' \\
	tex & `seb_1chirag_strata_1' & `seb_1chirag_strata_2' & `seb_1chirag_strata_3' \\
	tex \addlinespace
	tex \({TREATMENT}_j \times {NGO}_j\) & `bst_1treatment1chirag_strata_1' & `bst_1treatment1chirag_strata_2' & `bst_1treatment1chirag_strata_3' \\
	tex & `seb_1treatment1chirag_strata_1' & `seb_1treatment1chirag_strata_2' & `seb_1treatment1chirag_strata_3' \\
	tex \midrule
	tex Control mean & `control_mean' & `control_mean' & `control_mean'  \\
	tex District fixed-effects & Yes & Yes & Yes \\
	tex Household-level controls & No & No & Yes \\
	tex \(N\) & `N_1' & `N_2' & `N_3' \\
	tex Adjusted \(R^{2}\) & `ar2_1' & `ar2_2' & `ar2_2'   \\
	tex \bottomrule
	tex \end{tabular}
	tex \begin{tablenotes}
	tex \footnotesize
	tex {\setlength\labelsep{0pt}
	tex \item \textit{Notes}. The outcome variable is an indicator that equals 1 if household \(i\) in hamlet \(j\) purchased at least one of the two ICS promoted during the intervention. Column (1) presents aggregated results; results are disaggregated by NGO and non-NGO villages (as shown in Equation \ref{e:purchase_rates}) in columns (2) and (3). Baseline household-level controls for household size and number of children under five are included in column (3). Standard errors (in parentheses) are clustered at the hamlet level. \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\).}
	tex \end{tablenotes}
	tex \end{threeparttable}
	tex \end{table}
texdoc close

********************************************************************************

* END
